package com.hanxu.controller;

import com.hanxu.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/user")
public class UserController {

    /**
     * http://locahost:8080/user/t1?name =xxx
     * @param name
     * @return
     * 加入@RequestParam("username")
     * 就必须http://locahost:8080/username/t1?name =xxx
     */
    @RequestMapping("/t1")
    public String test1(@RequestParam("username") String name , Model model){
        //1.接受前端传回的参数
        System.out.println(name);
        //2.将返回的结果再传给前端
        model.addAttribute("msg","传回的结果"+name);
        //3.视图跳转
        return "test";
    }


    /**
     * 接受一个实体类 http://localhost:8080/user/t2?id=1&name=xxx&age=3
     * 自动解析实体类 user
     * @param user
     * @param model
     * @return
     */
    @RequestMapping("/t2")
    public String test2(User user, Model model){
        //1.接受前端传回的参数
        System.out.println(user);
        //2.将返回的结果再传给前端
        model.addAttribute("msg","传回的结果"+user.name);
        //3.视图跳转
        return "test";
    }



}
